package com.example.beautymakeup.dao;


import com.example.beautymakeup.pojo.Hot;
import com.example.beautymakeup.pojo.Shop;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface ShopDao {
    @Select("select * from shop where uid = #{uid};")
    Shop getByUid( int uid);

    //    用户端获取上架的商品信息
    @Select("select * from shop where status = 0 order by grade DESC limit #{page},#{size};")
    List<Shop> get(@Param("page") int page, @Param("size") int size);
    //    管理端获取上架的商品信息
    @Select("select shop.*,c.title from shop,classify c where shop.classifyId = c.uid order by grade DESC limit #{page},#{size};")
    List<Shop> getAll(@Param("page") int page, @Param("size") int size);

    @Select("select shop.*,c.title from shop,classify c where shop.classifyId = c.uid and classifyId = #{classifyId} order by grade DESC;")
    List<Shop> getByTypeId(int classifyId);

    @Update("update shop set hotId = #{hotId}, grade = #{grade},shopName = #{shopName},shopImage = #{shopImage},particulars = #{particulars},count = #{count},price = #{price},original = #{original} where uid = #{uid};")
    int update(Shop shop);

    @Update("update shop set classifyId = #{classifyId} where uid = #{uid};")
    int updateType(Shop shop);

    @Insert("insert into shop(shopName,shopImage,particulars,count,price,classifyId,original,grade) values (#{shopName},#{shopImage},#{particulars},#{count},#{price},#{classifyId},#{original},#{grade});")
    int add(Shop shop);

//    用户端获取总数
    @Select("select count(*) from shop where status = 0;")
    int getCount();
//  管理端获取总数
    @Select("select count(*) from shop;")
    int getAllCount();

    @Update("update shop set status = #{status} where uid = #{uid};")
    int ban(Shop shop);

    @Delete("delete from shop where uid = #{uid};")
    int delete(Shop shop);
//    设置热门
    @Update("update shop set hotId = #{hotId} where uid = #{uid};")
    int hot(Shop shop);

//     获取热门的shop
    @Select("select * from shop where hotId = #{hotId} and status = 0 order by grade DESC limit #{page},#{size};")
    List<Shop> getHotShop(@Param("hotId") int hotId,@Param("page") int page, @Param("size") int size);

    @Select("select count(*) from shop where hotId = #{hotId} and status = 0;")
    int getHotCount(int hotId);

    //     获取类型的shop
    @Select("select * from shop where classifyId = #{classifyId} and status = 0 order by grade DESC limit #{page},#{size};")
    List<Shop> getTypeShop(@Param("classifyId") int classifyId,@Param("page") int page, @Param("size") int size);

    @Select("select count(*) from shop where classifyId = #{classifyId} and status = 0;")
    int getTypeCount(int classifyId);

    @Select("select * from shop where (shopName like CONCAT('%', #{shopName}, '%') or particulars like CONCAT('%', #{shopName}, '%')) and status = 0 order by grade DESC limit #{page},#{size};")
    List<Shop> search(@Param("shopName") String shopName,@Param("page") int page, @Param("size") int size);

    @Select("select count(*) from shop where (shopName like CONCAT('%', #{shopName}, '%') or particulars like CONCAT('%', #{shopName}, '%')) and status = 0;")
    int getSearchCount(String shopName);

    @Select("select count from shop where uid = #{uid};")
    int getShopCount(int uid);

    @Update("update shop set count = count - #{count} where uid = #{uid};")
    int updateCount(Shop shop);

    @Update("update shop set count = count + #{count} where uid = #{uid};")
    int addCount(Shop shop);
}
